Export this symbol for loading an XPM from memory.
authorHavoc Pennington <hp@pobox.com>
Fri, 22 Oct 1999 21:05:16 +0000 (21:05 +0000)
committerHavoc Pennington <hp@src.gnome.org>
Fri, 22 Oct 1999 21:05:16 +0000 (21:05 +0000)
1999-10-22  Havoc Pennington  <hp@pobox.com>

* src/io-xpm.c (image_load_xpm_data): Export this symbol for
loading an XPM from memory.

* src/gdk-pixbuf-io.c (gdk_pixbuf_new_from_xpm_data): New
function, loads pixbuf from xpm data
(image_handler_load): Add g_return_if_fail() to ensure the same
module isn't loaded twice. Add g_module_symbol() to scan for XPM
loader function.

gdk-pixbuf/ChangeLog
gdk-pixbuf/gdk-pixbuf-io.c
gdk-pixbuf/io-xpm.c

index 205f992518f33be39c82a22b143fe438025b4012..96942bb05861663e7c38623c31726423dca8c798 100644 (file)
@@ -1,3 +1,14 @@
+1999-10-22  Havoc Pennington  <hp@pobox.com>
+
+       * src/io-xpm.c (image_load_xpm_data): Export this symbol for 
+       loading an XPM from memory.
+
+       * src/gdk-pixbuf-io.c (gdk_pixbuf_new_from_xpm_data): New
+       function, loads pixbuf from xpm data
+       (image_handler_load): Add g_return_if_fail() to ensure the same
+       module isn't loaded twice. Add g_module_symbol() to scan for XPM 
+       loader function.
+
 1999-10-22  Federico Mena Quintero  <federico@redhat.com>
 
        * src/io-png.c (image_load): Patch from Kristian Hogsberg
index 42a06c3c4f91f8a43c6d1f7db519d785acf2c3a5..4c467beca64ec07073bf3c3ec865cd550210f973 100644 (file)
@@ -140,15 +140,17 @@ static struct {
        gboolean (* format_check) (guchar *buffer, int size);
        GModule *module;
        GdkPixbuf *(* load) (FILE *f);
+        GdkPixbuf *(* load_xpm_data) (const gchar **data);
 } file_formats [] = {
-       { "png",  pixbuf_check_png,  NULL, NULL },
-       { "jpeg", pixbuf_check_jpeg, NULL, NULL },
-       { "tiff", pixbuf_check_tiff, NULL, NULL },
-       { "gif",  pixbuf_check_gif,  NULL, NULL },
-       { "xpm",  pixbuf_check_xpm,  NULL, NULL },
+       { "png",  pixbuf_check_png,  NULL, NULL, NULL },
+       { "jpeg", pixbuf_check_jpeg, NULL, NULL, NULL },
+       { "tiff", pixbuf_check_tiff, NULL, NULL, NULL },
+       { "gif",  pixbuf_check_gif,  NULL, NULL, NULL },
+#define XPM_FILE_FORMAT_INDEX 4
+       { "xpm",  pixbuf_check_xpm,  NULL, NULL, NULL },
 #if 0
-       { "bmp",  pixbuf_check_bmp,  NULL, NULL },
-       { "ppm",  pixbuf_check_ppm,  NULL, NULL },
+       { "bmp",  pixbuf_check_bmp,  NULL, NULL, NULL },
+       { "ppm",  pixbuf_check_ppm,  NULL, NULL, NULL },
 #endif
        { NULL, NULL, NULL, NULL }
 };
@@ -161,6 +163,8 @@ image_handler_load (int idx)
        GModule *module;
        void *load_sym;
 
+        g_return_if_fail(file_formats[idx].module == NULL);
+        
        module_name = g_strconcat ("pixbuf-", file_formats [idx].module_name, NULL);
        path = g_module_build_path (PIXBUF_LIBDIR, module_name);
        g_free (module_name);
@@ -176,6 +180,9 @@ image_handler_load (int idx)
 
        if (g_module_symbol (module, "image_load", &load_sym))
                file_formats [idx].load = load_sym;
+
+        if (g_module_symbol (module, "image_load_xpm_data", &load_sym))
+               file_formats [idx].load_xpm_data = load_sym;
 }
 
 \f
@@ -224,3 +231,26 @@ gdk_pixbuf_new_from_file (const char *filename)
        g_warning ("Unable to find handler for file: %s", filename);
        return NULL;
 }
+
+GdkPixbuf *
+gdk_pixbuf_new_from_xpm_data (const gchar **data)
+{
+        GdkPixbuf *(* load_xpm_data) (const gchar **data);
+        GdkPixbuf *pixbuf;
+        
+        if (file_formats[XPM_FILE_FORMAT_INDEX].load_xpm_data == NULL) {
+                image_handler_load(XPM_FILE_FORMAT_INDEX);
+        }
+
+        if (file_formats[XPM_FILE_FORMAT_INDEX].load_xpm_data == NULL) {
+                g_warning("Can't find gdk-pixbuf module for parsing inline XPM data");
+                return NULL;
+        } else {
+                load_xpm_data = file_formats[XPM_FILE_FORMAT_INDEX].load_xpm_data;
+        }
+
+        pixbuf = load_xpm_data(data);
+
+        return pixbuf;
+}
+                              
index c6d74a4d31b407ac17a2d0deab252575486c7a76..babd096a6eaecbaa7e12cefaf030e592b8acb7de 100644 (file)
@@ -57,7 +57,7 @@ struct file_handle {
 };
 
 struct mem_handle {
-       gchar **data;
+       const gchar **data;
        int offset;
 };
 
@@ -437,3 +437,18 @@ image_load (FILE *f)
 
        return pixbuf;
 }
+
+/* Shared library entry point for memory loading */
+GdkPixbuf *
+image_load_xpm_data (const gchar **data)
+{
+        GdkPixbuf *pixbuf;
+        struct mem_handle h;
+
+        h.data = data;
+        h.offset = 0;
+        
+       pixbuf = pixbuf_create_from_xpm (mem_buffer, &h);
+        
+       return pixbuf;
+}